package com.yuan.fmmall.config;

import com.yuan.fmmall.interceptor.CheckTokenInterceptor;
import com.yuan.fmmall.interceptor.SetTimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Yuan
 */
//拦截器配置
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private CheckTokenInterceptor checkTokenInterceptor;

    @Autowired
    private SetTimeInterceptor setTimeInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截受限资源（访问条件：已登录）
        registry.addInterceptor(checkTokenInterceptor)
                .addPathPatterns("/shopcart/**")
                .addPathPatterns("/orders/**")
                .addPathPatterns("/useraddr/**")
                .excludePathPatterns("/user/**");
        //拦截所有资源（主要是为了拦截非限制资源）
        registry.addInterceptor(setTimeInterceptor).addPathPatterns("/**");
    }
}
